package Controller;

import Util.JDBCUtill;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import pojo.teacher;

import java.util.List;

public class TeacherController {
    @FXML
    private TableView<teacher> teacherTable;
    @FXML
    private TableColumn<teacher, String>  TIdFile;
    @FXML
    private TableColumn<teacher, String> TNaFile;
    @FXML
    private TableColumn<teacher, String> TitleFile;
    @FXML
    private TableColumn<teacher, String> CNaFile;

    @FXML
    private TableColumn<teacher, String>CTmFile;

    @FXML
    private Button addbut;

    @FXML
    private Button changebut;

    @FXML
    private Button deletebut;

    @FXML
    private Button teacherbut;
    @FXML
    private Button userbut;


    @FXML
    private Button CheckBut;
    @FXML
    void initialize() {
        System.out.println(Main.SharedData.isAdmin);
        if(Main.SharedData.isAdmin==1) {
            teacherbut.setVisible(true);
            userbut.setVisible(true);
            addbut.setVisible(true);
            changebut.setVisible(true);
            deletebut.setVisible(true);
        }
        getDates();
    }
    private void getDates() {
        List<teacher> teachers = JDBCUtill.readTeacherlDate();
        TIdFile.setCellValueFactory(new PropertyValueFactory<>("TId"));
        TNaFile.setCellValueFactory(new PropertyValueFactory<>("TNa"));
        TitleFile.setCellValueFactory(new PropertyValueFactory<>("Title"));
        CNaFile.setCellValueFactory(new PropertyValueFactory<>("CNa"));
        CTmFile.setCellValueFactory(new PropertyValueFactory<>("CTm"));
        teacherTable.setItems(FXCollections.observableArrayList(teachers));
    }

    @FXML
    public void ClassInternationControl(ActionEvent event) {
        Main.changeView("ClassRoom.fxml");
    }
    @FXML
    void TeacherInternationControl(ActionEvent event) {
        initialize();
    }


    @FXML
    void UserInternationControl(ActionEvent event) {
        Main.changeView("user-view.fxml");
    }
}
